winsafe\gui\native_controls/
tab_item.rs1use crate::co;
2use crate::decl::*;
3use crate::gui::*;
4use crate::msg::*;
5use crate::prelude::*;
6
7#[derive(Clone, Copy)]
16pub struct TabItem<'a> {
17 owner: &'a Tab,
18 index: u32,
19}
20
21impl<'a> TabItem<'a> {
22 #[must_use]
23 pub(in crate::gui) const fn new(owner: &'a Tab, index: u32) -> Self {
24 Self { owner, index }
25 }
26
27 #[must_use]
29 pub const fn index(&self) -> u32 {
30 self.index
31 }
32
33 pub unsafe fn delete(&self) {
41 unsafe {
42 self.owner
43 .hwnd()
44 .SendMessage(tcm::DeleteItem { index: self.index })
45 }
46 .unwrap();
47 }
48
49 #[must_use]
52 pub fn lparam(&self) -> SysResult<isize> {
53 let mut tci = TCITEM::default();
54 tci.mask = co::TCIF::PARAM;
55
56 unsafe {
57 self.owner
58 .hwnd()
59 .SendMessage(tcm::GetItem { index: self.index, item: &mut tci })?;
60 }
61
62 Ok(tci.lParam)
63 }
64
65 pub fn set_lparam(&self, lparam: isize) -> SysResult<Self> {
70 let mut tci = TCITEM::default();
71 tci.mask = co::TCIF::PARAM;
72 tci.lParam = lparam;
73
74 unsafe {
75 self.owner
76 .hwnd()
77 .SendMessage(tcm::SetItem { index: self.index, item: &mut tci })?;
78 }
79 Ok(*self)
80 }
81
82 pub fn set_text(&self, text: &str) -> SysResult<Self> {
87 let mut wtext = WString::from_str(text);
88 let mut tci = TCITEM::default();
89 tci.mask = co::TCIF::TEXT;
90 tci.set_pszText(Some(&mut wtext));
91
92 unsafe {
93 self.owner
94 .hwnd()
95 .SendMessage(tcm::SetItem { index: self.index, item: &mut tci })?;
96 }
97 Ok(*self)
98 }
99
100 #[must_use]
103 pub fn text(&self) -> SysResult<String> {
104 let mut buf = WString::new_alloc_buf(64); let mut tci = TCITEM::default();
106 tci.mask = co::TCIF::TEXT;
107 tci.set_pszText(Some(&mut buf));
108
109 unsafe {
110 self.owner
111 .hwnd()
112 .SendMessage(tcm::GetItem { index: self.index, item: &mut tci })?;
113 }
114 Ok(buf.to_string())
115 }
116}